package com.musemun.common;

/**
 * <p>
 *  返回值封装工具类
 * </p>
 *
 * @author ZWYZY
 * @since 2020/4/21
 */
public class ResultUtil {
    public static<T> CommonResult<T> success(T t) {
        CommonResult<T> result = new CommonResult<>();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMsg(ResultCode.SUCCESS.getMsg());
        result.setData(t);
        return result;
    }
//    public static<T> Result_Auto<T> change(){
//        Result_Auto<T> result = new Result_Auto<>();
//        result.setCode(ResultCode.CHANGE.getCode());
//        result.setMsg(ResultCode.CHANGE.getMsg());
//        return result;
//    }

    public static CommonResult success() {
        return success(null);
    }

    public static<T> CommonResult<T> error(Integer code, String msg) {
        CommonResult<T> result = new CommonResult<>();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(null);
        return result;
    }

    public static<T> CommonResult<Object> error(Integer code, String msg, String data) {
        CommonResult<Object> result = new CommonResult<>();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static<T> CommonResult<T> error(ResultCode resultCode) {
        CommonResult<T> result = new CommonResult<>();
        result.setCode(resultCode.getCode());
        result.setMsg(resultCode.getMsg());
        result.setData(null);
        return result;
    }



}
